<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>会员收货地址</title>
    <!--{include file='comm/comm_region.tpl'}-->
</head>
<body>
<div style="width:100%;padding: 5px;">

    <table id="flex" style="display:none"></table>

    <br>
    <div class="panel panel-default" id="address_edit_box">

        <div class="panel-heading"><span>收货地址</span></div>

        <form class="form-horizontal" role="form" id="address_form">
            <div class="panel-body">
                <div class="form-group">
                    <label for="cust_name" class="col-sm-2 control-label">收货人</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="custName" name="custName" placeholder="收货人" style="width: 150px;">
                    </div>
                </div>
                <div class="form-group">
                    <label for="province_list" class="col-sm-2 control-label">所在地区</label>
                    <div class="col-sm-10">
                        <select class="form-control col-sm-2" id="province_list" name="provinceid" style="width: 150px;margin-right: 10px;">
                            <option value="">请选择...</option>
                        </select>
                        <select class="form-control col-sm-2" id="city_list" name="cityid" style="width: 150px;margin-right: 10px;">
                            <option value="">请选择...</option>
                        </select>
                        <select class="form-control col-sm-2" id="county_list" name="countyid" style="width: 150px;">
                            <option value="">请选择...</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label for="address" class="col-sm-2 control-label">收货地址</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="address" name="address" style="width: 470px;" placeholder="收货地址">
                    </div>
                </div>
                <div class="form-group">
                    <label for="iMobile" class="col-sm-2 control-label">手机号码</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="mobile" name="mobile" placeholder="手机号码" style="width: 150px;">
                    </div>
                </div>
                <div class="form-group">
                    <label for="iPhone" class="col-sm-2 control-label">固定电话</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="phone" name="phone" placeholder="固定电话" style="width: 150px;">
                        <span class="help-block red">“手机号码”和“固定电话”至少填写一项</span>
                        <input type="hidden" name="deliverID" id="deliverID" value="0">
                        <input type="hidden" id="pcustID" name="pcustID" value="<!--{$pcustID}-->">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">&nbsp;</label>
                    <div class="col-sm-10">
                        <input type="button" class="btn btn-success" onclick="deliver.save();" value="保存" />&nbsp;&nbsp;&nbsp;
                        <input type="button" class="btn btn-default" onclick="deliver.cancel();" value="取消" />
                    </div>
                </div>
            </div>
        </form>
    </div>

</div>

<script type="text/javascript">

    //全局变量
    var pcustID = <!--{$pcustID}-->;

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/customer/deliver.ajax?operFlg=3&pcustID=<!--{$pcustID}-->",
        dataType: "json",
        colModel : [
            {display: "操作", width : 100, align: "center"},
            {display: "收货人", width : 80, align: "left"},
            {display: "收货地址", width : 350,align:"left"},
            {display: "联系手机", width : 110,align:"center"},
            {display: "联系电话", width : 110,align:"right"}
        ],
        sortname: "deliverID",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        height: 200,
        showTableToggleBtn: true,
        onSubmit: function() {
            var dt = $('#search_form').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });

    E.region.init();

    var deliver = {

        load: function() {
            $("#flex").flexReload();
        },

        cancel: function( deliverID ) {
            document.getElementById('address_form').reset();
        },

        edit: function( deliverID ) {

            E.region.clearP( 'province_list' );
            E.region.clearC( 'city_list' );
            E.region.clearA( 'county_list' );

            E.loadding.open('正在查询收货地址，请稍候...');
            E.ajax_get({
                url: '/invokingAjax-backend/customer/deliver.ajax?operFlg=4',
                data: {
                    pcustID: pcustID,
                    deliverID: deliverID
                },
                call: function( o ) {
                    E.loadding.close();
                    if (o.code == 200) {
                        $('#custName').val(o.data.custName);
                        E.region.init({
                            pid: o.data.provinceid,
                            cid: o.data.cityid,
                            ccid: o.data.countyid
                        });
                        $('#address').val(o.data.address);
                        $('#mobile').val(o.data.mobile);
                        $('#phone').val(o.data.phone);
                        $('#deliverID').val(o.data.deliverID);
                    } else {
                        E.alert(o.message);
                    }
                }
            });

        },

        save: function() {

            E.region.backAdd('address_form', function( o ) {
                E.loadding.close();
                if (o.code == 200) {
                    deliver.load();
                    deliver.cancel();
                    E.alert('收货地址保存成功', 2);
                } else {
                    E.alert(o.message);
                }
            });

        },

        del: function( deliverID ) {

            E.confirm('您确认要删除该收货地址吗？', function() {

                E.loadding.open('正在删除，请稍候...');
                E.ajax_get({
                    url: '/invokingAjax-backend/customer/deliver.ajax?operFlg=2',
                    data: {
                        pcustID: pcustID,
                        id: deliverID
                    },
                    call: function( o ) {
                        E.loadding.close();
                        if (o.code == 200) {
                            deliver.load();
                            E.alert(o.message, 2);
                        } else {
                            E.alert(o.message);
                        }
                    }
                });

            });

        }

    };

</script>

</body>

</html>
